<%--
  Created by IntelliJ IDEA.
  User: hkw14
  Date: 2021/5/2
  Time: 20:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加用户</title>
    <link rel="stylesheet" href="${ctx}/resource/layui/css/layui.css">
    <style>
        .formInfo{
            position:absolute;
            top:50%;
            left:50%;
            transform:translate(-50%,-50%);
        }
    </style>
</head>
<body>
<div class="formInfo">
<form class="layui-form layui-form-pane" lay-filter="editData" style="padding:10px" >
    <div class="layui-form-item ">
        <label class="layui-form-label">
            员工姓名:
        </label>
        <div class="layui-input-inline">
            <input class="layui-input" name="realName">
        </div>
    </div>
    <div class="layui-form-item ">
        <label class="layui-form-label">
            入职时间:
        </label>
        <div class="layui-input-inline">
            <input class="layui-input" name="entryDate" id="entryDate" placeholder="yyyy-MM-dd">
        </div>
    </div>
    <div class="layui-form-item ">
        <label class="layui-form-label">
            员工部门:
        </label>
        <div class="layui-input-inline">
            <select id="departmentID" name="departmentID">
                <option value="">选择部门</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item ">
        <label class="layui-form-label">
            出生日期:
        </label>
        <div class="layui-input-inline">
            <input class="layui-input" id="birth" type="text" placeholder="yyyy-MM-dd">
        </div>
    </div>
    <div class="layui-form-item ">
        <label class="layui-form-label">
            性别角色:
        </label>
        <div class="layui-input-inline">
            <select name="sex">
                <option value="2">女</option>
                <option value="1">男</option>
            </select>
        </div>
    </div>
    <div class="layui-inline">
    <button id="save" class="layui-btn" type="button" lay-filter="submitBtn" >提交</button>
    <button type="reset" class="layui-btn layui-btn-warm" >重置</button>
    </div>
</form>
</div>
<script src="${ctx}/resource/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form',"laydate",'layer'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#birth' //指定元素
        });
        laydate.render({
            elem: '#entryDate' //指定元素
        });

        $.ajax({
            url:'emp.do?service=departList',
            success:function(res){
                if(rs.code == 200){
                    var datal = res.data.list;
                    for(var i =0;i<res.data.list.length;i++){
                        $("#departmentID").append("<option value=\""+datal[i].iD+"\">"+datal[i].departmentName+"</option>");
                    }
                    //重新渲染
                    layui.form.render("select");
                }else{
                    layer.msg(res.message);
                }
            }
        });

        $("#save").click(function () {
            var entryDate = $("#entryDate").val();
            var birth = $("#birth").val();
            var realName = $("#realName").val();
            var departmentID = $("#departmentID").val();
            var sex = $("#sex").val();
            console.log(userName+realName+password+role);
            $.post("emp.do?service=add",{'entryDate':entryDate,'realName':realName,'departmentID':departmentID,'birth':birth,'sex':sex},function(rs){
                if(rs.code != 200){
                    layer.msg(rs.msg);
                }else{
                    layer.msg("用户添加成功");
                }
            });
        })
    });
</script>
</body>
</html>
